***生成处置年份
gen policy=year-treatYear
***生成虚拟变量
forvalues i =6(-1)1{
  gen Pre_`i' = (policy == -`i' & km2 == 1) 
}

gen Current = (policy == 0 & km2 == 1)

forvalues j = 1(1)6{
  gen  Post_`j' = (policy == `j' & km2 == 1)
}
****平行趋势回归
xi: reghdfe y2 Pre* Current Post* $l1control if year>=2008 , absorb(co_firm co_year ) vce(cluster co_firm) 
est store reg1

***画图
*参数说明：
*			keep:		图片中保留的期数
*			coeflabels:	每一期在图片中展示的标签名称（横坐标）
*			vertical addplot:	在图片中绘制的元素 
*			lcolor:		线条颜色


coefplot, keep(Pre_5 Pre_4 Pre_3 Pre_2 Pre_1 Current Post_1 Post_2 Post_3  Post_4 Post_5 Post_6 Post_7 ) ///
coeflabels(Pre_5=t-5 Pre_4=t-4 Pre_3=t-3 Pre_2=t-2 Pre_1=t-1 ///
Current=t Post_1=t+1 Post_2=t+2 Post_3=t+3 Post_4=t+4 Post_5=t+5 Post_6=t+6 Post_7=t+7) /// 
vertical addplot(line @b @at,lcolor(gsl3)) yline(0,lcolor("black")) ytitle(`"{fontface "黑体":系数}"',size(large)) xtitle(`"{fontface "宋体":年份}"',size(large)) ///
ciopts(recast(rcap) lcolor(gsl9)) levels(95) title("y2",size(huge) )  note( "(a)",place(s) size(large)) mcolor(gsl6) 
***保存图片
graph save Graph 平行趋势\t1y2.gph,replace
***合并多个图片
**记得手动调整图片框的大小
graph combine 平行趋势检验Lnoinc.gph 平行趋势检验Lnoinc2.gph,iscale(1) xsize(10) by(north) ///
subtitle("State’s location", prefix) ///
subtitle("Based on Region", suffix)
